package com.jic.manager.impl;

import java.lang.Long;
import java.util.List;

import com.jic.manager.entity.SysRoleMenu;
import com.jic.manager.mapper.SysRoleMenuMapper;
import com.jic.manager.request.SysRoleMenuRequest;
import com.jic.manager.service.SysRoleMenuService;
import com.jic.common.base.vo.Page;
import com.jic.common.base.vo.PageResult;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 角色授权表
 * @author : 
 * @email : 
 * @since : 2020-02-26 09:38:53
 * @version : v1.0.0
 */
@Service
public class SysRoleMenuServiceImpl implements SysRoleMenuService{

    @Resource
    private SysRoleMenuMapper sysRoleMenuMapper;

    @Override
    public long insert(SysRoleMenu sysRoleMenu) {
        long flag = sysRoleMenuMapper.insert(sysRoleMenu);
        return flag;
    }

    @Override
    public long delete(Long id) {
        return sysRoleMenuMapper.delete(id);
    }

    @Override
    public long deleteByRoleId(Long roleId) {
        return sysRoleMenuMapper.deleteByRoleId(roleId);
    }

    @Override
    public long update(SysRoleMenu sysRoleMenu) {
        return sysRoleMenuMapper.update(sysRoleMenu);
    }

    @Override
    public SysRoleMenu queryByPrimaryKey(Long id){
        return sysRoleMenuMapper.queryByPrimaryKey(id);
    }

    @Override
    public List<SysRoleMenu> query(SysRoleMenu sysRoleMenu){
        return sysRoleMenuMapper.query(sysRoleMenu);
    }

    @Override
    public PageResult<SysRoleMenu> queryPage(SysRoleMenu sysRoleMenu, Page pageQuery) {
        //计算下标
        int startIndex = (pageQuery.getStart() - 1) * pageQuery.getLimit();
        List<SysRoleMenu> list = sysRoleMenuMapper.queryPage(startIndex, pageQuery.getLimit(), sysRoleMenu);
        long count = sysRoleMenuMapper.queryPageCount(sysRoleMenu);
        PageResult pageResult = new PageResult();
        pageResult.setRows(list);
        pageResult.setTotal(count);
        return pageResult;
    }

    @Override
    public long insertList(List<SysRoleMenuRequest> roleMenus) {
        return sysRoleMenuMapper.insertList(roleMenus);
    }
}